package com.neuedu.redis.controller;

import com.neuedu.redis.utils.RedisUtil;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 项目 data-redis-springboot
 *
 * @author 张金山
 * @version 1.0
 * 说明 Redis测试
 * @date 2021/6/2 16:00
 */
@RestController
@RequestMapping("/redis")
public class RedisController {


    @Resource
    RedisTemplate redisTemplate;


    @Resource
    RedisUtil redisUtil;

    /**
     * http://127.0.0.1/redis/hello
     * @return
     */
    @RequestMapping("/set")
    public String set() {

        redisTemplate.opsForValue().set("user","张三");
        return "欢迎访问 redis-data";
    }


    @RequestMapping("/get")
    public String get() {
        String user = (String) redisTemplate.opsForValue().get("user");
        return user;
    }




    /**
     * http://127.0.0.1/redis/uset
     * @return
     */
    @RequestMapping("/uset")
    public String uset() {

        redisUtil.set("utilKey","utilValue");
        return "欢迎访问 redis-data";
    }


    /**
     * http://127.0.0.1/redis/uget
     * @return
     */
    @RequestMapping("/uget")
    public String uget() {
        String user = redisUtil.get("utilKey");
        return user;
    }
}
